import axios from "axios"
import * as actionType from "./actionType"

const changeLoginState = () => ({
  type: actionType.CHANGELOGIN,
  value: true
})

const changeLogoutState = () => ({
  type: actionType.CHANGELOGOUT,
  value: false
})

export const login = (account, password) => {
  return (dispatch) => {
    axios.get("/api/login.json?account=" + account + "&password= " + password).then((res) => {
      const result = res.data.data;
      if (result) {
        dispatch(changeLoginState())
      } else {
        alert("登录失败")
      }
    })
  }
}

export const logout = () => {
  return (dispatch) => {
    console.log(44)
    dispatch(changeLogoutState())
  }
}
